package com.zui.entity.trade;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.Table;
import javax.persistence.Transient;

import com.zui.entity.BaseEntity;
import com.zui.entity.BaseUuidEntity;
import com.zui.entity.party.Party;
import com.zui.entity.product.Geo;
import com.zui.entity.product.Product;
import com.zui.entity.setup.Uom;

@Entity
@org.hibernate.annotations.Entity(
		selectBeforeUpdate = true,dynamicInsert = true, dynamicUpdate=true)
@Table(name="trade")
public class Trade  extends BaseUuidEntity{
	private static final long serialVersionUID = 1L;
	
	private TradeType tradeType;
	/**
	 * Title for the trade;
	 */
	private String title;
	private Product product;
	/**
	 * Trade price
	 */
	private Long price;
	private Uom currencyUom;
	/**
	 * Owner party of the trading message.
	 */
	private Party ownerParty;

	private String commercialFlag;
	/**
	 * contact
	 */
	private String contact;
	/**
	 * qq/msn/etc.
	 */
	private String im;
	/**
	 * Mobile phone or fixed phone
	 */
	private String phone;
	/**
	 * Trading geo information for city.
	 */
	private Geo geoCity;	
	/**
	 * Trading geo information.
	 */
	private Geo geoDistrict;
	/**
	 * Trading geo information.
	 */
	private Geo geoBusinessArea;
	
	private Integer viewedCount = 0;
	
	private String[] featureIds = new String[5];
	@Transient
	public String[] getFeatureIds() {return featureIds;}
	
	private String[] imageIds;
	@Transient
	public String[] getImageIds() {return imageIds;}
	//*********** utility methods *****************************

	
	//*********** getter *****************************
	@ManyToOne
	@JoinColumn(name="tradeTypeId")
	public TradeType getTradeType() {		return tradeType;	}

	@Column(length=50)
	public String getTitle() {		return title;	}
	@ManyToOne(cascade = {CascadeType.ALL})
	@JoinColumn(name="productId")
	public Product getProduct() {	return product;	}
	@ManyToOne(cascade = {CascadeType.PERSIST, CascadeType.MERGE})
	//@Cascade(org.hibernate.annotations.CascadeType.SAVE_UPDATE)
	@JoinColumn(name="ownerPartyId")
	public Party getOwnerParty() {		return ownerParty;	}

	public Long getPrice() {	return price;	}
	@Column(length=50)
	public String getContact() {		return contact;	}
	@Column(length=50)
	public String getIm() {	return im;	}
	@Column(length=50)
	public String getPhone() {	return phone;	}

	@ManyToOne @JoinColumn(name="currencyUomId")
	public Uom getCurrencyUom() {
		return currencyUom;
	}
	@ManyToOne
	@JoinColumn(name="geoCityId")
	public Geo getGeoCity() {	return geoCity;	}
	@ManyToOne
	@JoinColumn(name="geoDistrictId")
	public Geo getGeoDistrict() {	return geoDistrict;	}

	@ManyToOne
	@JoinColumn(name="geoBusinessAreaId")
	public Geo getGeoBusinessArea() {	return geoBusinessArea;	}
	
	public Integer getViewedCount() {	return viewedCount;	}

	public void setGeoDistrict(Geo geoDistrict) {
		this.geoDistrict = geoDistrict;
	}


	public void setGeoBusinessArea(Geo geoBusinessArea) {
		this.geoBusinessArea = geoBusinessArea;
	}

	@Column(length=1)
	public String getCommercialFlag() {	return commercialFlag;}


	public void setCommercialFlag(String commercialFlag) {
		this.commercialFlag = commercialFlag;
	}


	//*********** setter *******************
	public void setTradeType(TradeType tradeType) {
		this.tradeType = tradeType;
	}

	public void setTitle(String title) {
		this.title = title;
	}

	public void setProduct(Product product) {
		this.product = product;
	}

	public void setOwnerParty(Party ownerParty) {
		this.ownerParty = ownerParty;
	}

	public void setPrice(Long price) {
		this.price = price;
	}

	public void setContact(String contact) {
		this.contact = contact;
	}

	public void setIm(String im) {
		this.im = im;
	}

	public void setPhone(String phone) {
		this.phone = phone;
	}

	public void setCurrencyUom(Uom currencyUom) {
		this.currencyUom = currencyUom;
	}
	public void setFeatureIds(String[] featureIds) {
		this.featureIds = featureIds;
	}

	public void setImageIds(String[] imageIds) {
		this.imageIds = imageIds;
	}
	public void setViewedCount(Integer viewedCount) {
		this.viewedCount = viewedCount;
	}
	public void setGeoCity(Geo geoCity) {
		this.geoCity = geoCity;
	}
	
}
